package com.itheima.web.service.impl.sms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.service.sms.NewProductService;
import com.itheima.vo.sms.NewProduct;
import com.itheima.web.mapper.sms.NewProductMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import java.util.List;

@DubboService
public class NewProductServiceImpl extends ServiceImpl<NewProductMapper, NewProduct> implements NewProductService {
    @Override
    public Page<NewProduct> getPage(Integer pageNum, Integer pageSize, String productName, Integer recommendStatus) {
        Page<NewProduct> page=new Page<>();
        LambdaQueryWrapper<NewProduct> nplqw=new LambdaQueryWrapper<>();
        nplqw.like(Strings.isNotEmpty(productName),NewProduct::getProductName,productName);
        nplqw.eq(recommendStatus!=null,NewProduct::getRecommendStatus,recommendStatus);
        this.page(page,nplqw);
        return page;
    }

    @Override
    public void updateByStatus(List<Integer> ids, Integer recommendStatus) {
        List<NewProduct> newProducts = this.listByIds(ids);
        for (NewProduct newProduct : newProducts) {
            newProduct.setRecommendStatus(recommendStatus);
        }

        this.updateBatchById(newProducts);
    }
}
